/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Admin
 * Date: 2022-05-13
 * Time: 15:22
 */
public class MyQueue {

    static class Node {
        public int val;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }

    public int count;
    public Node head;
    public Node last;

    /**
     * 尾结点辅助添加
     * @param data
     */
    public void offer(int data) {
        Node node = new Node(data);

        if( head == null) {
            this.head = node;
            this.last = node;
        } else {
            last.next = node;
            last = node;
        }
        count++;
    }

    public boolean Empty() {
        return count==0;
    }

   public int poll() {
        if(Empty()) {
            throw new RuntimeException("空指针异常");
        }

       int ret = head.val;
        head = head.next;
        if(head == null) {
            last = null;
        }
        count--;
        return ret;
   }

   public int peek() {
        if(Empty()) {
            throw new RuntimeException("空指针异常");
        }
       int ret = head.val;
        return ret;
   }
}
